package com.shuyuansystem.service.impl;

import com.shuyuansystem.dao.LoginMapper;
import com.shuyuansystem.dao.UserMapper;
import com.shuyuansystem.pojo.User;
import com.shuyuansystem.service.LoginService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean register(User user){
        //调用注册方法
        loginMapper.register(user);
        return true;
    }

    @Override
    public boolean login(User user) {
        loginMapper.login(user);
        return true;
    }



    @Override
    public String checkUserType(User user) {
        return loginMapper.checkUserType(user.getUsername());
    }

    @Override
    public String findUserId(User user) {

        return loginMapper.findUserId(user);
    }

    @Override
    public boolean validateUser(String username, String password) {
        // 调用 Mapper 层的方法进行验证
        return userMapper.validateUser(username, password);
    }
    @Override
    public boolean changePassword(String username, String newPassword) {
        int rows = userMapper.updatePassword(username, newPassword);
        return rows > 0;
    }

    @Override
    public User findUserByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }
}
